#include <REGX52.H>
#include <INTRINS.h>
#include "Delay.h"
#include "LCD1602.h"
#include "MatrixKey.h"
unsigned char KeyNum;
unsigned int Password,Count;
void main()
{
		LCD_Init();
	LCD_ShowString(1,3,"Password:");
		while(1)
		{
				KeyNum = MatrixKey();
				if(KeyNum)//如果KeyNum不为0就显示
				{
						if(KeyNum<=10)//如果S1~S10按键被按下 输入密码
						{
							  if(Count<4)
								  {
								     Password*=10;//左移一位
									   Password+=KeyNum%10;//获取一位密码
									   Count++;//计次加一
									}
									LCD_ShowNum(2,7,Password,4); //更新显示
						}
						if(KeyNum == 11)
            {
								if(Password==2345)//如果密码等于正确结果
								{
									LCD_ShowString(1,12,"OK ");
									Password = 0;    //密码清零
									Count=0;         //计次清零
									LCD_ShowNum(2,7,Password,4); //更新显示
									
								}
								else
								{
									LCD_ShowString(1,12,"ERR");
									Password = 0;    //密码清零
									Count=0;         //计次清零
									LCD_ShowNum(2,7,Password,4); //更新显示
								}
						}
						if(KeyNum == 12)//如果S12被按下 取消
            {
							Password = 0;    //密码清零
							Count=0;         //计次清零
							LCD_ShowNum(2,7,Password,4); //更新显示
							LCD_ShowString(1,12,"   ");//清零顺便把提示也清空
						
						}
		    }
    }
}